//
//  KRNoNetCell.m
//  cookBook
//
//  Created by kuroken on 16/1/28.
//  Copyright © 2016年 kuroken. All rights reserved.
//

#import "KRNoNetCell.h"
#import <PureLayout.h>

// cell重用标识
static NSString * const KRNoNet = @"noNet";

@interface KRNoNetCell ()
@property (nonatomic, weak) UIImageView *noNetImageView;
@property (nonatomic, weak) UILabel *labelView;
@end

@implementation KRNoNetCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    KRNoNetCell *cell = [tableView dequeueReusableCellWithIdentifier:KRNoNet];
    if (!cell) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:KRNoNet];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self setupSubview];
        [self addConstraint];
    }
    return self;
}

- (void)setNoNetHint:(NSString *)hint
{
    [self.labelView setText:[NSString stringWithFormat:@"%@\n点击屏幕重新加载\n", hint]];
}

/**
 *  初始化子控件
 */
- (void)setupSubview
{
    UIImageView *noNetImageView = [[UIImageView alloc] init];
    [noNetImageView setImage:[UIImage imageNamed:@"nonet_default"]];
    [self.contentView addSubview:noNetImageView];
    self.noNetImageView = noNetImageView;

    UILabel *labelView= [[UILabel alloc] init];
    [labelView setTextColor:[UIColor grayColor]];
    [labelView setFont:[UIFont systemFontOfSize:15]];
    [labelView setNumberOfLines:0];
    [labelView setTextAlignment:NSTextAlignmentCenter];
    [self.noNetImageView addSubview:labelView];
    self.labelView = labelView;

}

/**
 *  添加约束
 */
- (void)addConstraint
{
    [self.noNetImageView autoCenterInSuperview];
    [self.noNetImageView autoSetDimensionsToSize:self.noNetImageView.image.size];
    
    [self.labelView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
